/******************************************************************************
	Cobalt - utility libraries for building XNA games
	Copyright (C) 2008 Philip Djonov

	This program is free software; you can redistribute it and/or modify it
	under the terms of the GNU General Public License as published by the Free
	Software Foundation; either version 2 of the License, or (at your option)
	any later version.

	This program is distributed in the hope that it will be useful, but
	WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
	or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
	for more details.

	You should have received a copy of the GNU General Public License along
	with this program; if not, write to the
	
		Free Software Foundation, Inc.
		51 Franklin Street, Fifth Floor
		Boston, MA  02110-1301, USA.
******************************************************************************/

using System;
using System.Collections.Generic;
using System.Drawing;
using System.Drawing.Text;

using Microsoft.Xna.Framework.Content.Pipeline;
using Microsoft.Xna.Framework.Content.Pipeline.Graphics;

namespace Cobalt.Content.Pipeline.Graphics.Font
{
	public class SpriteFontContent : ContentItem
	{
		private int[] characters;
		public int[] Characters { get { return characters; } set { characters = value; } }

		private Texture2DContent[] imageSheets;
		public Texture2DContent[] ImageSheets { get { return imageSheets; } set { imageSheets = value; } }

		private FontPointContent[] fontPoints;
		public FontPointContent[] FontPoints { get { return fontPoints; } set { fontPoints = value; } }
	}

	public class FontPointContent
	{
		private float size;
		public float Size { get { return size; } set { size = value; } }

		private float ascent;
		public float Ascent { get { return ascent; } set { ascent = value; } }

		private float lineSpacing;
		public float LineSpacing { get { return lineSpacing; } set { lineSpacing = value; } }

		private GlyphContent[] glyphs;
		public GlyphContent[] Glyphs { get { return glyphs; } set { glyphs = value; } }
	}

	public class GlyphContent
	{
		private int character;
		public GlyphContent( int character )
		{
			this.character = character;
		}

		public int Character { get { return character; } }
		public bool IsUppercase { get { return char.IsUpper( (char)character ); } }

		internal static readonly byte[][] EmptyImage = new byte[1][] { new byte[1] };

		private byte[][] imageData = EmptyImage;
		public byte[][] ImageData
		{
			get { return imageData; }
			set
			{
				if( value == null )
					value = EmptyImage;

				if( value[0] == null || value[0].Length == 0 )
					throw new ArgumentException();
				for( int i = 1; i < value.Length; i++ )
				{
					if( value[i] == null || value[i].Length != value[0].Length )
						throw new ArgumentException();
				}

				imageData = value;
			}
		}

		public Size ImageDataSize { get { return new Size( imageData[0].Length, imageData.Length ); } }

		private Size size;
		public Size Size { get { return size; } set { size = value; } }

		private PointF drawOffset;
		public PointF DrawOffset { get { return drawOffset; } set { drawOffset = value; } }

		private float abcKernA;
		public float AbcKernA { get { return abcKernA; } set { abcKernA = value; } }
		private float abcKernB;
		public float AbcKernB { get { return abcKernB; } set { abcKernB = value; } }
		private float abcKernC;
		public float AbcKernC { get { return abcKernC; } set { abcKernC = value; } }

		private Texture2DContent imageSheet;
		public Texture2DContent ImageSheet { get { return imageSheet; } set { imageSheet = value; } }
		private Rectangle imageSheetRect;
		public Rectangle ImageSheetRectangle { get { return imageSheetRect; } set { imageSheetRect = value; } }

		private GlyphContent otherCap;
		public GlyphContent OtherCap { get { return otherCap; } set { otherCap = value; } }
	}
}